﻿public partial class Solution
{
    public int Fib(int n)
    {
        int result = 0;
        // 斐波那契数列的前两个数
        if (n is 0 or 1)
        {
            result = n;
        }
        else
        {
            // 初始化前两个数
            int prev = 0;
            int curr = 1;
            // 循环计算第n个斐波那契数
            for (int i = 2; i <= n; i++)
            {
                int next = prev + curr;
                prev = curr;
                curr = next;
            }
            // 当前值为第n个斐波那契数
            result = curr;
        }
        return result;
    }
}